<template>
  <div class="xptjContainer">
    <!-- 商品信息顶部滑动组件 -->
    <div class="mui-slider slider-head">
      <div class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted" style="touch-action: none;">
        <div class="mui-scroll trans-wdq">
          <a :class="['mui-control-item',item.id == 0 ? 'mui-active' : '']" @tap='getproductInfor(item.id)' v-for="item in products" :key='item.id'>
            {{item.name}}
          </a>
        </div>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul class="productContainor">
      <router-link class="pcon" to="/shop/xptj/infor" v-for='item in list' :key='item.id' tag="li">
        <img v-lazy = "item.pic">
        <div class="Pinfor">{{item.infor}}</div>
        <div class="price">{{item.price}}</div>
      </router-link>
    </ul>
  </div>
</template>
<script>
// 导入MUI的JS文件
import mui from '../lib/mui/js/mui.min.js'
export default {
  data () {
    return {
      products: [],
      list: []
    }
  },
  created () {
    this.getdata()
    this.getproductInfor(0)
  },
  mounted () {
    // 初始化顶部mui组件的滑动块
    mui('mui-slider>.mui-scroll-wrapper').scroll({
      deceleration: 0.0004
    })
  },
  methods: {
    // 获取分类列表
    getdata () {
      this.axios.get('productInfor.json').then(
        rs => {
          this.products = rs.data
        })
    },
    // 获取商品信息
    getproductInfor (id) {
      console.log(id)
      this.axios.get('ProductDetail' + id + '.json').then(
        rs => {
          this.list = rs.data
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.xptjContainer{
  width: 99%;
  .slider-head{
    position: relative;
  }
  .mui-scroll{
    margin: auto;
    display: flex;
    router-link{
      flex: 1;
    }
  }
}
.productContainor{
  width: 99%;
  margin: auto;
  height: 75vh;
  overflow: auto;
  border-radius: 2%;
  margin: 0;
  .pcon:nth-child(odd){
    margin-right: 2px;
  }
  .pcon{
    display: inline-block;
    position: relative;
    width: 49%;
    height: 37vh;
    border-radius: 1%;
    margin-bottom: 2px;
    border: 2px solid #ccc;
    img{
      width: 100%;
      height: 80%;
      margin-bottom: -10px;
    }
    .Pinfor{
      width: 95%;
      height: 12%;
      overflow: hidden;
      margin: auto;
      font-size: 0.65rem;
    }
    .price{
      color: #c44;
      font-size: 1rem;
      height: 5%;
      line-height: 0.9rem;
    }
  }
}
</style>
